namespace TXLooker.WorkItemExtention.WIQL
{
    using System;

    public class NodeTableName : NodeItem
    {
        private object m_tag;

        public NodeTableName(NodeName n) : base(NodeType.TableName, n.Value)
        {
            base.StartOffset = n.StartOffset;
            base.EndOffset = n.EndOffset;
        }

        public NodeTableName(string s) : base(NodeType.TableName, s)
        {
        }

        public override void Bind(IExternal e, NodeTableName tableContext, NodeFieldName fieldContext)
        {
            if (e != null)
            {
                this.m_tag = e.FindTable(base.Value);
                Tools.EnsureSyntax(this.m_tag != null, SyntaxError.TableDoesNotExist, this);
            }
            base.Bind(e, tableContext, fieldContext);
        }

        public override string ToString()
        {
            return Tools.FormatName(base.Value);
        }

        public override DataType DataType
        {
            get
            {
                return DataType.Table;
            }
        }

        public override bool IsConst
        {
            get
            {
                return true;
            }
        }

        public object Tag
        {
            get
            {
                return this.m_tag;
            }
        }
    }
}

